package com.songcha.sakura.mvvm.comic.episode

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.songcha.library_base.interfaces.IApiResult
import com.songcha.library_base.mvvm.base.BaseRepository
import com.songcha.library_base.mvvm.base.BaseViewModel
import com.songcha.sakura.bean.ComicDetailBean
import com.songcha.sakura.bean.ComicM3u8Bean

class ComicEpisodeViewModel(app: Application) : BaseViewModel<ComicM3u8Repository>(app) {
    val downloadM3u8Url=MutableLiveData<ComicM3u8Bean?>()
    val playM3u8Url=MutableLiveData<ComicM3u8Bean?>()
    var episodeList:MutableList<ComicDetailBean.EpisodeBean> = mutableListOf()
    var thumb:String=""
    //var isDownload=false
    //var isOper=false

    fun initUrl(){
        downloadM3u8Url.value=null
        playM3u8Url.value=null
    }

    /* fun getComicDetail(href:String){
        viewModelScope.launch {
            val json=JSONObject()
            json.put("href",href)
            ComicDetailRepository().sendRequest<ComicDetailBean>(json){
                _comicDetail.value=it
            }
        }

    }*/

    fun getM3u8(episodeHref:String,isDownload:Boolean){
        handleApiDataObserver((repository as ComicM3u8Repository).getEpisodeM3u8(episodeHref),object :
            IApiResult<ComicM3u8Bean> {
            override fun onSuccess(bean: ComicM3u8Bean) {
                if(isDownload)
                    downloadM3u8Url.value=bean
                else
                    playM3u8Url.value=bean
            }
        },true)


    }


}